args Controls lab keep ipw CreativityMeasure


preserve

* setup
replace Creativity=creativityt_`CreativityMeasure'_7

local SC  SC_I33  SC_I42  SC_I46 SC_I50  SC_I55 



* calculate ipw weights 
foreach y of local SC {	
	if `ipw'==1{
		ge io=`y'!=.
		qui logit io $HDC_0
		drop io
		predict p_`y', pr
	}

	if `ipw'==0{
		ge  p_`y'=1
	}
		
}	


foreach y of local SC {	
	if `ipw'==1{
		local a=substr("`y'",-3,.) /* find instrument and age*/
		ge io=`y'!=. if SE_`a'==0
		qui logit io $HDC_0
		drop io
		predict pse_`y', pr
	}

	if `ipw'==0{
		ge  pse_`y'=1
	}
		
}	





* reshape to long dataset
reshape long lwage_I SC_I p_SC_I SE_I, i(NCDSID) j(age)
su p_*
drop if age==23

ta SC_I, nol
recast double SC_I
replace SC_I=round(SC_I*10)
ta SC_I, gen(Occ)
su Occ*

local O Occ1 Occ2 Occ3 Occ4 Occ5 Occ6


* estimation 
foreach o of local O {

	rifhdreg `o' `Controls' [pweight=1/p_SC], rif(mean) cluster(NCDSID)
	
	mat b = e(b)
	mat b = b'
	svmat b
	qui su b1 if b1!=0
	mat define p= r(N)
	drop b1
	qui estadd scalar Par=p[1,1]
	qui estadd scalar Ni=e(N_clust) 
	qui estadd scalar mdv=e(rifmean)
	
	est sto esall_`o'

}

* estimation 
foreach o of local O {

	qui rifhdreg `o' `Controls' if SE==0 [pweight=1/p_SC], rif(mean) cluster(NCDSID)
	
	mat b = e(b)
	mat b = b'
	svmat b
	qui su b1 if b1!=0
	mat define p= r(N)
	drop b1
	qui estadd scalar Par=p[1,1]
	qui estadd scalar Ni=e(N_clust) 
	qui estadd scalar mdv=e(rifmean)
	
	est sto esse_`o'

}



* count number of varibles
local count0: word count `O'
local count=`count0'+1

* without p-values
******************************************************************************************

* all individuals
local text0 "prehead( \vspace{.2cm}  \\ \multicolumn{4}{l}{\textbf{Panel A: All individuals}} \\ \multicolumn{4}{l}{\phantom{.}}   \\  \vspace{-.65cm}\\ ) "
local text  `text0' prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ )  posthead(\vspace{-.3cm}\\ \cline{2-`count'} )  postfoot(\vspace{-.3cm} \\ \hline ) 

local stP "stats( N mdv, fmt( %11.0gc %8.2f)  labels("Individual-year obs."  "Mean dep. var."))" 
esttab esall* using results/Tables/R_OLS_`lab'.tex, ///
replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) ".") nogaps   alignment(c) ///
mtitles("Professional" "\shortstack{Managerial \\\& Technical}" "\shortstack{Skilled \\non-manual}" "\shortstack{Skilled \\manual}" "\shortstack{Partly \\skilled}" "Unskilled") frag `stP'


local text0 "prehead( \vspace{.2cm}  \\ \multicolumn{4}{l}{\textbf{Panel B: Excluding self-employed}} \\ \multicolumn{4}{l}{\phantom{.}} \\ \vspace{-.65cm}\\ ) "
local text  `text0' prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ )  posthead(\vspace{-.3cm}\\ \cline{2-`count'}) 
local stP "stats( N mdv, fmt( %11.0gc %8.2f)  labels("Individual-year obs."  "Mean dep. var."))" 

* without anyone ever self employed
esttab esse* using results/Tables/R_OLS_`lab'.tex, ///
append `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) ".") nogaps   alignment(c) ///
mtitles("Professional" "\shortstack{Managerial \\\& Technical}" "\shortstack{Skilled \\non-manual}" "\shortstack{Skilled \\manual}" "\shortstack{Partly \\skilled}" "Unskilled") frag `stP'

* with p-values
******************************************************************************************

* all individuals
local text0 "prehead( \vspace{.2cm}  \\ \multicolumn{4}{l}{\textbf{Panel A: All individuals}} \\ \multicolumn{4}{l}{\phantom{.}}   \\  \vspace{-.65cm}\\ ) "
local text  `text0' prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ )  posthead(\vspace{-.3cm}\\ \cline{2-`count'} )  postfoot(\vspace{-.3cm} \\ \hline ) 

local stP "stats( N mdv, fmt( %11.0gc %8.2f)  labels("Individual-year obs."  "Mean dep. var."))" 
esttab esall* using results/Tables/R_OLS_`lab'p.tex, ///
replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) p(%9.4f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) p(par([ ]) fmt(%9.5f)) ".") nogaps   alignment(c) ///
mtitles("Professional" "\shortstack{Managerial \\\& Technical}" "\shortstack{Skilled \\non-manual}" "\shortstack{Skilled \\manual}" "\shortstack{Partly \\skilled}" "Unskilled") frag `stP'


local text0 "prehead( \vspace{.2cm}  \\ \multicolumn{4}{l}{\textbf{Panel B: Excluding self-employed}} \\ \multicolumn{4}{l}{\phantom{.}} \\ \vspace{-.65cm}\\ ) "
local text  `text0' prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ )  posthead(\vspace{-.3cm}\\ \cline{2-`count'}) 
local stP "stats( N mdv, fmt( %11.0gc %8.2f)  labels("Individual-year obs."  "Mean dep. var."))" 

* without anyone ever self employed
esttab esse* using results/Tables/R_OLS_`lab'p.tex, ///
append `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) p(par([ ]) fmt(%9.5f)) ".") nogaps   alignment(c) ///
mtitles("Professional" "\shortstack{Managerial \\\& Technical}" "\shortstack{Skilled \\non-manual}" "\shortstack{Skilled \\manual}" "\shortstack{Partly \\skilled}" "Unskilled") frag `stP'

















/*

* count number of varibles
local count0: word count `O'
local count=`count0'+1
local text0 "prehead( \vspace{.2cm}  \\ ) "
local text  `text0' prefoot( \cline{2-`count'}  \vspace{-.3cm}\\ )  posthead(\vspace{-.3cm}\\ \cline{2-`count'} )  postfoot(\vspace{-.3cm} \\ \hline ) 

* Stats
local stP "stats( N mdv, fmt( %11.0gc %8.2f)  labels("Individual-year obs."  "Mean dep. var."))" 

* all
esttab esall* using results/Tables/R_OLS_`lab'.tex, ///
replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) ".") nogaps   alignment(c) ///
mtitles("1" "2" "3I" "3II" "4" "5") frag `stP'

* without self employed
esttab esse* using results/Tables/R_OLS_nose_`lab'_nose.tex, ///
replace `text' se star(* 0.1 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) nonumbers collabels(none) ///
keep(Creativity `keep') refcat(Creativity ""  " " "", nolabel) ///
order(Creativity) varlabels(Creativity Creativity CogAbility "Cognitive ability") ///
cells(b(star fmt(3)) se(par) ".") nogaps   alignment(c) ///
mtitles("1" "2" "3I" "3II" "4" "5") frag `stP'


*/


est drop _all
restore

